﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sunboxsoft.ASMS.Server.Domain
{
    public class Constant
    {
        /// <summary>
        /// 分页时在一页获取所有数据
        /// </summary>
        public const int PageLimitAll = 99999;

        /// <summary>
        /// 种子key
        /// </summary>
        public static class SeedKeys
        {
            public const string BookingBill = "BookingBill.Seed";
            public const string MaintenceBill = "MaintenceBill.Seed";
            public const string SettlementBill = "SettlementBill.Seed";
            public const string RechargeBill = "RechargeBill.Seed";
            public const string WorkingBill = "WorkingBill.Seed";
            public const string MaterialRequisitionBill = "MaterialRequisitionBill.Seed";
            public const string CapitalIncreaseBill = "CapitalIncreaseBill.Seed";
            public const string CapitalDecreaseBill = "CapitalDecreaseBill.Seed";
            public const string StockIncreaseBill = "StockIncreaseBill.Seed";
            public const string StockDecreaseBill = "StockDecreaseBill.Seed";
        }

        /// <summary>
        /// 性别
        /// </summary>
        public static class Genders
        {
            /// <summary>
            /// 男性
            /// </summary>
            public const int Male = 1;
            /// <summary>
            /// 女性
            /// </summary>
            public const int Female = 2;

            /// <summary>
            /// 男性
            /// </summary>
            public static readonly IntCodeTextItem MaleItem = new IntCodeTextItem(Male, "男性");

            /// <summary>
            /// 女性
            /// </summary>
            public static readonly IntCodeTextItem FemaleItem = new IntCodeTextItem(Female, "女性");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[]{
                    MaleItem,
                    FemaleItem
                };
            }

            public static string GetText(int code)
            {
                if (code == Male)
                {
                    return MaleItem.Text;
                }
                else if (code == Female)
                {
                    return FemaleItem.Text;
                }
                return "unknown";
            }
        }

        /// <summary>
        /// 主数据编码
        /// </summary>
        public class MasterDataCodes
        {
            /// <summary>
            /// 国家
            /// </summary>
            public const string Country = "COUNTRY";
            /// <summary>
            /// 省
            /// </summary>
            public const string Province = "PROVINCE";
            /// <summary>
            /// 市
            /// </summary>
            public const string City = "CITY";
            /// <summary>
            /// 区
            /// </summary>
            public const string District = "DISTRICT";

            /// <summary>
            /// 客户类型
            /// </summary>
            public const string CustumerType = "CUSTOMERTYPE";

            /// <summary>
            /// 保险公司
            /// </summary>
            public const string InsuranceCompany = "INSURANCECOMPANY";

            /// <summary>
            /// 汽车品牌
            /// </summary>
            public const string AutomobileBrand = "AUTOBRAND";

            /// <summary>
            /// 汽车厂商
            /// </summary>
            public const string AutomobileMaker = "AUTOMAKER";
            /// <summary>
            /// 汽车系列
            /// </summary>
            public const string AutomobileSeries = "AUTOSERIES";
            /// <summary>
            /// 车型
            /// </summary>
            public const string AutomobileModel = "AUTOMODEL";

            /// <summary>
            /// 服务类别
            /// </summary>
            public const string ServiceCategory = "C08";

            /// <summary>
            /// 服务项目
            /// </summary>
            public const string ServiceItem = "C09";

            /// <summary>
            /// 物料单位
            /// </summary>
            public const string MaterialUnit = "MATERIALUNIT";
            /// <summary>
            /// 物料分类
            /// </summary>
            public const string MaterialCategory = "MATERIALCATEGORY";
            /// <summary>
            /// 物料品牌
            /// </summary>
            public const string MaterialBrand = "MATERIALBRAND";

            /// <summary>
            /// 支付渠道
            /// </summary>
            public const string PayChannel = "PAYCHANNCEL";

            /// <summary>
            /// 发票类型
            /// </summary>
            public const string InvoiceTypes = "INVOICETYPES";

            /// <summary>
            /// 销售渠道
            /// </summary>
            public const string SalesChannel = "SALESCHANNEL";
        }

        /// <summary>
        /// 预订单的状态
        /// </summary>
        public static class BookingBillStatus
        {
            /// <summary>
            /// 全部，查询的时候可用
            /// </summary>
            public const int All = 0;
            /// <summary>
            /// 正常
            /// </summary>
            public const int Normal = 1;
            /// <summary>
            /// 已到店
            /// </summary>
            public const int Working = 2;
            /// <summary>
            /// 已完结
            /// </summary>
            public const int Finished = 3;
            /// <summary>
            /// 已终止
            /// </summary>
            public const int Terminated = 4;
            /// <summary>
            /// 已超时
            /// </summary>
            public const int Timeout = 4;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem NormalItem = new IntCodeTextItem(Normal, "待到店");
            public static readonly IntCodeTextItem WorkingItem = new IntCodeTextItem(Working, "已到店");
            public static readonly IntCodeTextItem FinishedItem = new IntCodeTextItem(Finished, "已完成");
            public static readonly IntCodeTextItem TerminatedItem = new IntCodeTextItem(Terminated, "已取消");
            public static readonly IntCodeTextItem TimeoutItem = new IntCodeTextItem(Timeout, "已超时");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, NormalItem, WorkingItem, TerminatedItem };
            }

            public static string GetText(int code)
            {
                if (code == Normal)
                {
                    return NormalItem.Text;
                }
                else if (code == Working)
                {
                    return WorkingItem.Text;
                }
                else if (code == Finished)
                {
                    return FinishedItem.Text;
                }
                else if (code == Terminated)
                {
                    return TerminatedItem.Text;
                }
                else if (code == Timeout)
                {
                    return TimeoutItem.Text;
                }
                return code.ToString();
            }
        }

        /// <summary>
        /// 公共状态
        /// </summary>
        public static class CommonStatus
        {
            public const int ALL = 0;
            public const int Enabled = 1;
            public const int Disabled = 2;
            public const int Deleted = 3;
            public const int WaitAuditing = 4;
            public const int Rejected = 5;
            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(ALL, "全部");
            public static readonly IntCodeTextItem EnabledItem = new IntCodeTextItem(Enabled, "正常");
            public static readonly IntCodeTextItem DisabledItem = new IntCodeTextItem(Disabled, "已超时");
            public static readonly IntCodeTextItem DeletedItem = new IntCodeTextItem(Deleted, "已完成");
            public static readonly IntCodeTextItem WaitAuditingItem = new IntCodeTextItem(WaitAuditing, "已完成");
            public static readonly IntCodeTextItem RejectedItem = new IntCodeTextItem(Rejected, "已完成");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, EnabledItem, DisabledItem, DeletedItem };
            }
        }

        /// <summary>
        /// 资金变更类型
        /// </summary>
        public static class CapitalChangedType
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0;

            /// <summary>
            /// 入账-应收入账
            /// </summary>
            public const int IncreaseReceiveable = 0x01;
            /// <summary>
            /// 入账-其他入账
            /// </summary>
            public const int IncreaseOther = 0x02;
            /// <summary>
            /// 入账-维修单收银
            /// </summary>
            public const int IncreaseCheckoutMaintenanceBill = 0x03;
            /// <summary>
            /// 入账-套餐收银
            /// </summary>
            public const int IncreaseCheckoutPackagePurchaseBill = 0x04;
            /// <summary>
            /// 入账-充值收银
            /// </summary>
            public const int IncreaseCheckoutRechargeBill = 0x03;

            /// <summary>
            /// 出帐-采购货款支付
            /// </summary>
            public const int DecreasePurchaseMaterial = 0x71;
            /// <summary>
            /// 出帐-商品服务退款
            /// </summary>
            public const int DecreaseReturned = 0x72;
            /// <summary>
            /// 出帐-员工工资支付
            /// </summary>
            public const int DecreaseSalary = 0x73;
            /// <summary>
            /// 出帐-办公用品采购
            /// </summary>
            public const int DecreasePurchaseOffice = 0x74;
            /// <summary>
            /// 出帐-水电杂费
            /// </summary>
            public const int DecreaseUtilities = 0x75;
            /// <summary>
            /// 出帐-运营费用
            /// </summary>
            public const int DecreaseRunning = 0x76;
            /// <summary>
            /// 出帐-现金存款
            /// </summary>
            public const int DecreaseCashDeposits = 0x77;
            /// <summary>
            /// 出帐-应付款项
            /// </summary>
            public const int DecreasePayable = 0x78;
            /// <summary>
            /// 出帐-其他出账
            /// </summary>
            public const int DecreaseOther = 0x79;

            public static IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static IntCodeTextItem IncreaseReceiveableItem = new IntCodeTextItem(IncreaseReceiveable, "入账-应收入账");
            public static IntCodeTextItem IncreaseOtherItem = new IntCodeTextItem(IncreaseOther, "入账-其他入账");
            public static IntCodeTextItem IncreaseCheckoutMaintenanceBillItem = new IntCodeTextItem(IncreaseCheckoutMaintenanceBill, "入账-维修单收银");
            public static IntCodeTextItem IncreaseCheckoutPackagePurchaseBillItem = new IntCodeTextItem(IncreaseCheckoutPackagePurchaseBill, "入账-套餐收银");
            public static IntCodeTextItem IncreaseCheckoutRechargeBillItem = new IntCodeTextItem(IncreaseCheckoutRechargeBill, "入账-充值收银");
            

            public static IntCodeTextItem DecreasePurchaseMaterialItem = new IntCodeTextItem(DecreasePurchaseMaterial, "出帐-采购货款支付");
            public static IntCodeTextItem DecreaseReturnedItem = new IntCodeTextItem(DecreaseReturned, "出帐-商品服务退款");
            public static IntCodeTextItem DecreaseSalaryItem = new IntCodeTextItem(DecreaseSalary, "出帐-员工工资支付");
            public static IntCodeTextItem DecreasePurchaseOfficeItem = new IntCodeTextItem(DecreasePurchaseOffice, "出帐-办公用品采购");
            public static IntCodeTextItem DecreaseUtilitiesItem = new IntCodeTextItem(DecreaseUtilities, "出帐-水电杂费");
            public static IntCodeTextItem DecreaseRunningItem = new IntCodeTextItem(DecreaseRunning, "出帐-运营费用");
            public static IntCodeTextItem DecreaseCashDepositsItem = new IntCodeTextItem(DecreaseCashDeposits, "出帐-现金存款");
            public static IntCodeTextItem DecreasePayableItem = new IntCodeTextItem(DecreasePayable, "出帐-应付款项");
            public static IntCodeTextItem DecreaseOtherItem = new IntCodeTextItem(DecreaseOther, "出帐-其他出账");

            public static IntCodeTextItem[] EnumerateIncrease()
            {
                return new IntCodeTextItem[] { IncreaseCheckoutMaintenanceBillItem, IncreaseCheckoutPackagePurchaseBillItem, IncreaseCheckoutRechargeBillItem, IncreaseReceiveableItem, IncreaseOtherItem };
            }
            public static IntCodeTextItem[] EnumerateDecrease()
            {
                return new IntCodeTextItem[] { DecreasePurchaseMaterialItem, DecreaseReturnedItem,
               DecreaseSalaryItem,DecreasePurchaseOfficeItem, DecreaseUtilitiesItem,DecreaseRunningItem,
                DecreaseCashDepositsItem, DecreasePayableItem,DecreaseOtherItem };
            }
            public static IntCodeTextItem[] EnumerateAll()
            {
                return new IntCodeTextItem[] { AllItem, IncreaseCheckoutMaintenanceBillItem, 
                    IncreaseCheckoutPackagePurchaseBillItem, 
                    IncreaseCheckoutRechargeBillItem, 
                    IncreaseReceiveableItem, IncreaseOtherItem,
                    DecreasePurchaseMaterialItem, DecreaseReturnedItem,
                    DecreaseSalaryItem,DecreasePurchaseOfficeItem, DecreaseUtilitiesItem,DecreaseRunningItem,
                DecreaseCashDepositsItem, DecreasePayableItem,DecreaseOtherItem };
            }
            public static string GetText(int code)
            {
                IntCodeTextItem[] items = EnumerateAll();
                for (int index = 0; index < items.Length; index++)
                {
                    if (items[index].Code == code)
                    {
                        return items[index].Text;
                    }
                }
                return code.ToString();
            }
        }


        /// <summary>
        /// 资金往来角色类型
        /// </summary>
        public static class CapitalRoleTypes
        {
            /// <summary>
            /// 客户
            /// </summary>
            public const int Customer = 0x01;
            /// <summary>
            /// 供应商
            /// </summary>
            public const int Supplier = 0x02;
            /// <summary>
            /// 员工
            /// </summary>
            public const int Staff = 0x03;
            /// <summary>
            /// 其他
            /// </summary>
            public const int Other = 0x04;

            public static readonly IntCodeTextItem CustomerItem = new IntCodeTextItem(Customer, "客户");
            public static readonly IntCodeTextItem SupplierItem = new IntCodeTextItem(Supplier, "供应商");
            public static readonly IntCodeTextItem StaffItem = new IntCodeTextItem(Staff, "员工");
            public static readonly IntCodeTextItem OtherItem = new IntCodeTextItem(Other, "其他");

            public static IntCodeTextItem[] EnumerateIncrease()
            {
                return new IntCodeTextItem[] { CustomerItem, SupplierItem, StaffItem, OtherItem };
            }

            public static IntCodeTextItem[] EnumerateDecrease()
            {
                return new IntCodeTextItem[] { CustomerItem, SupplierItem, StaffItem, OtherItem };
            }

            public static string GetText(int code)
            {
                if (code == CustomerItem.Code)
                {
                    return CustomerItem.Text;
                }
                else if (code == SupplierItem.Code)
                {
                    return SupplierItem.Text;
                }
                else if (code == StaffItem.Code)
                {
                    return StaffItem.Text;
                }
                else if (code == OtherItem.Code)
                {
                    return OtherItem.Text;
                }
                return string.Format("unkown{0}", code);
            }
        }

        /// <summary>
        /// 员工岗位码
        /// </summary>
        public static class StaffPosts
        {
            /// <summary>
            /// 计时
            /// </summary>
            public const string Technician = "P01";
            /// <summary>
            /// 销售经理
            /// </summary>
            public const string SalesManager = "P02";
        }

        /// <summary>
        /// 付费项目类型
        /// </summary>
        public static class PayItemTypes
        {
            /// <summary>
            /// 全部，用于查询
            /// </summary>
            public const int All = 0;
            /// <summary>
            /// 支付项目
            /// </summary>
            public const int Payment = 1;
            /// <summary>
            /// 优惠项目
            /// </summary>
            public const int Discount = 2;

            private static readonly IntCodeTextItem[] _items = new IntCodeTextItem[]{
                new IntCodeTextItem(All, "全部"),
                new IntCodeTextItem(Payment, "付费项"),
                new IntCodeTextItem(Discount, "优惠项"),
            };

            /// <summary>
            /// 枚举
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return _items;
            }

            public static string GetText(int code)
            {
                if (code == Payment)
                {
                    return "付费项";
                }
                else if (code == Discount)
                {
                    return "优惠项";
                }
                return string.Format("unknown{0}", code);
            }
        }

        /// <summary>
        /// 分成类型
        /// </summary>
        public static class CommissionTypes
        {
            /// <summary>
            /// for query
            /// </summary>
            public const int All = 0;

            /// <summary>
            /// 无
            /// </summary>
            public const int None = 1;

            /// <summary>
            /// 固定金额
            /// </summary>
            public const int Fixed = 2;

            /// <summary>
            /// 比例
            /// </summary>
            public const int Rate = 3;
            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem NoneItem = new IntCodeTextItem(None, "无提成");
            public static readonly IntCodeTextItem FixedItem = new IntCodeTextItem(Fixed, "固定金额");
            public static readonly IntCodeTextItem RateItem = new IntCodeTextItem(Rate, "按比例");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { NoneItem, FixedItem, RateItem };
            }

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] EnumerateAll()
            {
                return new IntCodeTextItem[] { AllItem, NoneItem, FixedItem, RateItem };
            }
        }

        /// <summary>
        /// 库存变更类型
        /// </summary>
        public static class StockChangeTypes
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0x00;

            /// <summary>
            /// 采购入库
            /// </summary>
            public const int IncreasePurchase = 0x01;

            /// <summary>
            /// 盘盈入库
            /// </summary>
            public const int IncreaseInventoryProfit = 0x02;

            /// <summary>
            /// 其他入库
            /// </summary>
            public const int IncreaseOther = 0x03;

            /// <summary>
            /// 退料入库
            /// </summary>
            public const int IncreaseReturned = 0x04;

            /// <summary>
            /// 盘亏出库
            /// </summary>
            public const int DecreaseInventoryLoss = 0x72;

            /// <summary>
            /// 其他出库
            /// </summary>
            public const int DecreaseOther = 0x73;

            /// <summary>
            /// 领料出库
            /// </summary>
            public const int DecreaseRequisition = 0x74;

            /// <summary>
            /// 报废出库
            /// </summary>
            public const int DecreaseScrap = 0x75;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem IncreasePurchaseItem = new IntCodeTextItem(IncreasePurchase, "采购入库");
            public static readonly IntCodeTextItem IncreaseInventoryProfitItem = new IntCodeTextItem(IncreaseInventoryProfit, "盘盈入库");
            public static readonly IntCodeTextItem IncreaseReturnedItem = new IntCodeTextItem(IncreaseReturned, "退料入库");
            public static readonly IntCodeTextItem IncreaseOtherItem = new IntCodeTextItem(IncreaseOther, "其他入库");

            public static readonly IntCodeTextItem DecreaseRequisitionItem = new IntCodeTextItem(DecreaseRequisition, "领料出库");
            public static readonly IntCodeTextItem DecreaseInventoryLossItem = new IntCodeTextItem(DecreaseInventoryLoss, "盘亏出库");
            public static readonly IntCodeTextItem DecreaseScrapItem = new IntCodeTextItem(DecreaseScrap, "报废出库");
            public static readonly IntCodeTextItem DecreaseOtherItem = new IntCodeTextItem(DecreaseOther, "其他出库");

            /// <summary>
            /// 获取全部
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] EnumerateAll()
            {
                return new IntCodeTextItem[] { AllItem, IncreasePurchaseItem,IncreaseInventoryProfitItem,IncreaseReturnedItem,IncreaseOtherItem,
                    DecreaseRequisitionItem, 
                    DecreaseInventoryLossItem, 
                    DecreaseScrapItem,
                    DecreaseOtherItem };
            }

            /// <summary>
            /// 获取入库类型
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] EnumerateIncrease()
            {
                return new IntCodeTextItem[] { IncreasePurchaseItem, IncreaseInventoryProfitItem, IncreaseReturnedItem, IncreaseOtherItem };
            }

            /// <summary>
            /// 获取出库类型
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] EnumerateDecrease()
            {
                return new IntCodeTextItem[] { DecreaseRequisitionItem, DecreaseInventoryLossItem, DecreaseScrapItem, DecreaseOtherItem };
            }


            public static string GetText(int code)
            {
                if (code == IncreasePurchase)
                {
                    return IncreasePurchaseItem.Text;
                }
                else if (code == IncreaseInventoryProfit)
                {
                    return IncreaseInventoryProfitItem.Text;
                }
                else if (code == IncreaseReturned)
                {
                    return IncreaseReturnedItem.Text;
                }
                else if (code == IncreaseOther)
                {
                    return IncreaseOtherItem.Text;
                }
                else if (code == DecreaseRequisition)
                {
                    return DecreaseRequisitionItem.Text;
                }
                else if (code == DecreaseInventoryLoss)
                {
                    return DecreaseInventoryLossItem.Text;
                }
                else if (code == DecreaseScrap)
                {
                    return DecreaseScrapItem.Text;
                }
                else if (code == DecreaseOther)
                {
                    return DecreaseOtherItem.Text;
                }
                return code.ToString();
            }
        }

        /// <summary>
        /// 库存查询类型
        /// </summary>
        public static class StockQueryTypes
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0;
            /// <summary>
            /// 有数量
            /// </summary>
            public const int HasAny = 1;
            /// <summary>
            /// 警告
            /// </summary>
            public const int HasWarning = 2;
            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem HasAnyItem = new IntCodeTextItem(HasAny, "有库存");
            public static readonly IntCodeTextItem HasWarningItem = new IntCodeTextItem(HasWarning, "警告");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, HasAnyItem, HasWarningItem };
            }
        }

        /// <summary>
        /// 经销模式
        /// </summary>
        public static class SalesModes
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0;

            /// <summary>
            /// 经销
            /// </summary>
            public const int Sell = 1;

            /// <summary>
            /// 代理
            /// </summary>
            public const int Proxy = 2;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem SellItem = new IntCodeTextItem(Sell, "经销");
            public static readonly IntCodeTextItem ProxyItem = new IntCodeTextItem(Proxy, "代理");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { SellItem, ProxyItem };
            }

            /// <summary>
            /// 枚举所有的状态,查询使用
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] EnumerateAll()
            {
                return new IntCodeTextItem[] { AllItem, SellItem, ProxyItem };
            }
        }

        /// <summary>
        /// 结算类型
        /// </summary>
        public static class SettlementTypes
        {
            public const int All = 0;

            /// <summary>
            /// 支付
            /// </summary>
            public const int ByPay = 1;

            /// <summary>
            /// 套餐
            /// </summary>
            public const int ByPackage = 2;

            public static readonly IntCodeTextItem ByPayItem = new IntCodeTextItem(ByPay, "自付");

            public static readonly IntCodeTextItem ByPackageItem = new IntCodeTextItem(ByPackage, "套餐");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[]{
                    ByPayItem,
                    ByPackageItem};
            }

            public static string GetText(int code)
            {
                if (code == ByPay)
                {
                    return ByPayItem.Text;
                }
                else if (code == ByPackage)
                {
                    return ByPackageItem.Text;
                }
                return string.Format("unknown{0}", code);
            }
        }

        /// <summary>
        /// 套餐项目类型
        /// </summary>
        public static class PackageItemTypes
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0;

            /// <summary>
            /// 服务项目
            /// </summary>
            public const int ServiceItem = 1;

            /// <summary>
            /// 代金券
            /// </summary>
            public const int Voucher = 2;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem ServiceItemItem = new IntCodeTextItem(ServiceItem, "服务项目");
            public static readonly IntCodeTextItem VoucherItem = new IntCodeTextItem(Voucher, "代金券");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { ServiceItemItem, VoucherItem };
            }

            /// <summary>
            /// 枚举所有的状态,查询使用
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] EnumerateAll()
            {
                return new IntCodeTextItem[] { AllItem, ServiceItemItem, VoucherItem };
            }

            public static string GetText(int code)
            {
                if (code == ServiceItem)
                {
                    return ServiceItemItem.Text;
                }
                else if (code == Voucher)
                {
                    return VoucherItem.Text;
                }
                return code.ToString();
            }
        }

        public static class PackageItemTargetDataType
        {
            /// <summary>
            /// 服务项目
            /// </summary>
            public const int ServiceItem = 1;
        }

        /// <summary>
        /// 维修服务单状态
        /// </summary>
        public static class MaintenanceBillStatus
        {
            public const int All = 0;
            public const int Disabled = 2;
            public const int Deleted = 3;

            /// <summary>
            /// 等待派工
            /// </summary>
            public const int WaitDispatching = 1;
            /// <summary>
            /// 施工中
            /// </summary>
            public const int Working = 4;
            /// <summary>
            /// 等待结算
            /// </summary>
            public const int WaitSettling = 6;

            /// <summary>
            /// 等待收银
            /// </summary>
            public const int WaitCheckOut = 7;
            /// <summary>
            /// 等待验收（交货）
            /// </summary>
            public const int WaitDelivery = 8;
            /// <summary>
            /// 已完成
            /// </summary>
            public const int Finished = 9;


            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem DisabledItem = new IntCodeTextItem(Disabled, "已锁定");
            public static readonly IntCodeTextItem DeletedItem = new IntCodeTextItem(Deleted, "已删除");
            public static readonly IntCodeTextItem WaitDispatchingItem = new IntCodeTextItem(WaitDispatching, "等待派工");
            public static readonly IntCodeTextItem WorkingItem = new IntCodeTextItem(Working, "施工中");
            public static readonly IntCodeTextItem WaitSettlingItem = new IntCodeTextItem(WaitSettling, "等待结算");
            public static readonly IntCodeTextItem WaitCheckOutItem = new IntCodeTextItem(WaitCheckOut, "等待收银");
            public static readonly IntCodeTextItem WaitDeliveryItem = new IntCodeTextItem(WaitDelivery, "等待验收");
            public static readonly IntCodeTextItem FinishedItem = new IntCodeTextItem(Finished, "已完成");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, WaitDispatchingItem, WorkingItem, WaitSettlingItem, WaitCheckOutItem, WaitDeliveryItem, FinishedItem };
            }

            /// <summary>
            /// 服务项目状态
            /// </summary>
            public static class ServiceItemStatus
            {
                /// <summary>
                /// 未派工
                /// </summary>
                public const int Wait = 0x01;
                /// <summary>
                /// 部分未派工
                /// </summary>
                public const int PartialWait = 0x02;
                /// <summary>
                /// 施工中
                /// </summary>
                public const int Working = 0x03;
                /// <summary>
                /// 全部派工，但是有部分还未完成
                /// </summary>
                public const int PartialWorking = 0x04;
                /// <summary>
                /// 已完成
                /// </summary>
                public const int Finished = 0x05;

                public static string GetText(int code)
                {
                    if (code == Wait)
                    {
                        return "未派工";
                    }
                    else if (code == PartialWait)
                    {
                        return "部分未派工";
                    }
                    else if (code == Working)
                    {
                        return "施工中";
                    }
                    else if (code == PartialWorking)
                    {
                        return "部分施工中";
                    }
                    else if (code == Finished)
                    {
                        return "施工中";
                    }
                    return code.ToString();
                }
            }

            /// <summary>
            /// 维修单的物料状态
            /// </summary>
            public static class MaterialStatus
            {
                /// <summary>
                /// 未领料
                /// </summary>
                public const int Wait = 0x01;

                /// <summary>
                /// 领料中
                /// </summary>
                public const int Requesting = 0x02;

                /// <summary>
                /// 领料完成
                /// </summary>
                public const int Finished = 0x03;

                public static string GetText(int code)
                {
                    if (code == Wait)
                    {
                        return "未领料";
                    }
                    else if (code == Requesting)
                    {
                        return "领料中";
                    }
                    else if (code == Finished)
                    {
                        return "领料完成";
                    }
                    return code.ToString();
                }
            }
        }

        /// <summary>
        /// 维修服务单查询状态
        /// </summary>
        public static class MaintenanceBillQueryStatus
        {
            public static readonly Item All = new Item("全部", new int[] { MaintenanceBillStatus.All }, null, null);
            public static readonly Item WaitDispatching = new Item("等待派工", new int[] { MaintenanceBillStatus.WaitDispatching, MaintenanceBillStatus.Working },
                new int[] { MaintenanceBillServiceItemStatus.Wait }, null);
            public static readonly Item WaitReuestMaterial = new Item("等待领料", new int[] { MaintenanceBillStatus.WaitDispatching, MaintenanceBillStatus.Working },
                null, new int[] { MaintenanceBillMaterialStatus.Wait });
            public static readonly Item Working = new Item("施工中", new int[] { MaintenanceBillStatus.Working },
                null, null);
            public static readonly Item WaitSettling = new Item("等待结算", new int[] { MaintenanceBillStatus.WaitSettling },
                null, null);
            public static readonly Item WaitCheckOut = new Item("等待收银", new int[] { MaintenanceBillStatus.WaitCheckOut },
                null, null);
            public static readonly Item WaitDelivery = new Item("等待出厂", new int[] { MaintenanceBillStatus.WaitDelivery },
                null, null);
            public static readonly Item Finished = new Item("完毕", new int[] { MaintenanceBillStatus.Finished },
                null, null);

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static Item[] Enumerate()
            {
                return new Item[] { All, WaitDispatching, WaitReuestMaterial, Working, WaitSettling, WaitCheckOut, WaitDelivery, Finished };
            }

            public class Item
            {
                public int[] StatusArray { get; set; }
                public int[] ServiceItemStatusArray { get; set; }
                public int[] MaterialStatusArray { get; set; }
                public string Name { get; set; }

                public Item(string name, int[] statusArray, int[] serviceItemStatusArray, int[] materialStatusArray)
                {
                    Name = name;
                    StatusArray = statusArray;
                    ServiceItemStatusArray = serviceItemStatusArray;
                    MaterialStatusArray = materialStatusArray;
                }
            }
        }

        /// <summary>
        /// 维修单的服务项目状态
        /// </summary>
        public static class MaintenanceBillServiceItemStatus
        {
            /// <summary>
            /// 未派工
            /// </summary>
            public const int Wait = 0x01;
            /// <summary>
            /// 施工中
            /// </summary>
            public const int Working = 0x02;
            /// <summary>
            /// 已完成
            /// </summary>
            public const int Finished = 0x03;

            public static string GetText(int code)
            {
                if (code == Wait)
                {
                    return "未派工";
                }
                else if (code == Working)
                {
                    return "施工中";
                }
                else if (code == Finished)
                {
                    return "已完成";
                }
                return code.ToString();
            }
        }

        /// <summary>
        /// 维修单的物料状态
        /// </summary>
        public static class MaintenanceBillMaterialStatus
        {
            /// <summary>
            /// 未领料
            /// </summary>
            public const int Wait = 0x01;

            /// <summary>
            /// 领料完成
            /// </summary>
            public const int Finished = 0x02;

            /// <summary>
            /// 已退料
            /// </summary>
            public const int Returned = 0x03;

            public static string GetText(int code)
            {
                if (code == Wait)
                {
                    return "未领料";
                }
                else if (code == Finished)
                {
                    return "领料完成";
                }
                else if (code == Returned)
                {
                    return "已退料";
                }
                return "unknown";
            }
        }

        /// <summary>
        /// 派工单状态
        /// </summary>
        public static class WorkingBillStatus
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0;
            /// <summary>
            /// 施工中
            /// </summary>
            public const int Enabled = 1;
            /// <summary>
            /// 已删除
            /// </summary>
            public const int Deleted = 2;
            /// <summary>
            /// 已完成
            /// </summary>
            public const int Finished = 3;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem EnabledItem = new IntCodeTextItem(Enabled, "施工中");
            public static readonly IntCodeTextItem DeletedItem = new IntCodeTextItem(Deleted, "已删除");
            public static readonly IntCodeTextItem FinishedItem = new IntCodeTextItem(Finished, "已竣工");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, EnabledItem, DeletedItem, FinishedItem };
            }
        }

        /// <summary>
        /// 领料单状态
        /// </summary>
        public static class MaterialRequisitionStatus
        {
            /// <summary>
            /// 全部
            /// </summary>
            public const int All = 0;

            /// <summary>
            /// 已完成
            /// </summary>
            public const int Finished = 1;

            /// <summary>
            /// 已退料
            /// </summary>
            public const int Returned = 2;

            /// <summary>
            /// 已删除,暂不使用
            /// </summary>
            public const int Deleted = 3;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem FinishedItem = new IntCodeTextItem(Finished, "已领料");
            public static readonly IntCodeTextItem ReturnedItem = new IntCodeTextItem(Returned, "已退料");
            public static readonly IntCodeTextItem DeletedItem = new IntCodeTextItem(Deleted, "已删除");

            /// <summary>
            /// 枚举所有可用的状态
            /// </summary>
            /// <returns></returns>
            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, FinishedItem, ReturnedItem };
            }
        }

        /// <summary>
        /// 持续时间
        /// </summary>
        public static class DurationTypes
        {
            public const int OneMonth = 0x01;
            public const int TwoMonth = 0x02;
            public const int ThreeMonth = 0x03;
            public const int FourMonth = 0x04;
            public const int FiveMonth = 0x05;
            public const int SixMonth = 0x06;
            public const int SevenMonth = 0x07;
            public const int EightMonth = 0x08;
            public const int NineMonth = 0x09;
            public const int TenMonth = 0x0A;
            public const int ElevenMonth = 0x0B;
            public const int OneYear = 0x0C;
            public const int TwoYear = 0x0D;
            public const int ThreeYear = 0x0E;
            public const int Custom = 0xFF;

            public static readonly IntCodeTextItem OneMonthItem = new IntCodeTextItem(OneMonth, "1个月");
            public static readonly IntCodeTextItem TwoMonthItem = new IntCodeTextItem(TwoMonth, "2个月");
            public static readonly IntCodeTextItem ThreeMonthItem = new IntCodeTextItem(ThreeMonth, "3个月");
            public static readonly IntCodeTextItem FourMonthItem = new IntCodeTextItem(FourMonth, "4个月");
            public static readonly IntCodeTextItem FiveMonthItem = new IntCodeTextItem(FiveMonth, "5个月");
            public static readonly IntCodeTextItem SixMonthItem = new IntCodeTextItem(SixMonth, "6个月");
            public static readonly IntCodeTextItem SevenMonthItem = new IntCodeTextItem(SevenMonth, "7个月");
            public static readonly IntCodeTextItem EightMonthItem = new IntCodeTextItem(EightMonth, "8个月");
            public static readonly IntCodeTextItem NineMonthItem = new IntCodeTextItem(NineMonth, "9个月");
            public static readonly IntCodeTextItem TenMonthItem = new IntCodeTextItem(TenMonth, "10个月");
            public static readonly IntCodeTextItem ElevenMonthItem = new IntCodeTextItem(ElevenMonth, "11个月");
            public static readonly IntCodeTextItem OneYearItem = new IntCodeTextItem(OneYear, "1年");
            public static readonly IntCodeTextItem TwoYearItem = new IntCodeTextItem(TwoYear, "2年");
            public static readonly IntCodeTextItem ThreeYearItem = new IntCodeTextItem(ThreeYear, "3年");
            public static readonly IntCodeTextItem CustomItem = new IntCodeTextItem(Custom, "自定义");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[]{OneMonthItem,
                    TwoMonthItem,ThreeMonthItem,FourMonthItem,FiveMonthItem,
                    SixMonthItem,SevenMonthItem,EightMonthItem,NineMonthItem,
                    TenMonthItem,ElevenMonthItem,OneYearItem,TwoYearItem,ThreeYearItem,CustomItem
                };
            }

            /// <summary>
            /// 根据code换算出实际的天数
            /// </summary>
            /// <param name="code"></param>
            /// <returns></returns>
            public static int GetDurationValue(int code)
            {
                if (code < OneYear)
                {
                    return 30 * code;
                }
                else if (code <= ThreeYear)
                {
                    return 365 * (ThreeYear - OneYear + 1);
                }
                else
                {
                    return 0;
                }
            }
        }

        /// <summary>
        /// 油量
        /// </summary>
        public static class OilMass
        {
            public const int Full = 8;
            public const int Eight1 = 1;
            public const int Eight2 = 2;
            public const int Eight3 = 3;
            public const int Eigth4 = 4;
            public const int Eight5 = 5;
            public const int Eight6 = 6;
            public const int Eight7 = 7;

            public static readonly IntCodeTextItem FullItem = new IntCodeTextItem(Full, "满箱");
            public static readonly IntCodeTextItem Eight1Item = new IntCodeTextItem(Eight1, "1/8箱");
            public static readonly IntCodeTextItem Eight2Item = new IntCodeTextItem(Eight2, "2/8箱");
            public static readonly IntCodeTextItem Eight3Item = new IntCodeTextItem(Eight3, "3/8箱");
            public static readonly IntCodeTextItem Eigth4Item = new IntCodeTextItem(Eigth4, "4/8箱");
            public static readonly IntCodeTextItem Eight5Item = new IntCodeTextItem(Eight5, "5/8箱");
            public static readonly IntCodeTextItem Eight6Item = new IntCodeTextItem(Eight6, "6/8箱");
            public static readonly IntCodeTextItem Eight7Item = new IntCodeTextItem(Eight7, "7/8箱");

            public static IntCodeTextItem[] EnumerateAll()
            {
                return new IntCodeTextItem[]{
                    FullItem,Eight1Item,Eight2Item,Eight3Item,Eigth4Item,Eight5Item,Eight6Item,Eight7Item
                };
            }

            /// <summary>
            /// 编码转换为数值
            /// </summary>
            /// <param name="code"></param>
            /// <returns></returns>
            public static float GetValue(int code)
            {
                if (code == Eight1)
                {
                    return 0.125f;
                }
                else if (code == Eight2)
                {
                    return 0.25f;
                }
                else if (code == Eight3)
                {
                    return 0.375f;
                }
                else if (code == Eigth4)
                {
                    return 0.5f;
                }
                else if (code == Eight5)
                {
                    return 0.625f;
                }
                else if (code == Eight6)
                {
                    return 0.75f;
                }
                else if (code == Eight7)
                {
                    return 0.875f;
                }
                return 1.0f;
            }
        }

        /// <summary>
        /// 套餐的可见性
        /// </summary>
        public static class PackageAccessibility
        {
            /// <summary>
            /// 所有人
            /// </summary>
            public const int Everyone = 0x01;
            /// <summary>
            /// vip
            /// </summary>
            public const int VIP = 0x02;
            /// <summary>
            /// 非vip
            /// </summary>
            public const int NonVIP = 0x03;
        }

        /// <summary>
        /// 套餐实例项目变更类型
        /// </summary>
        public static class PackageInstanceItemChangedTypes
        {
            /// <summary>
            /// 增加
            /// </summary>
            public const int Increase = 0x01;
            /// <summary>
            /// 减少
            /// </summary>
            public const int Decrease = 0x02;

            public static readonly IntCodeTextItem IncreaseItem = new IntCodeTextItem(Increase, "退回");
            public static readonly IntCodeTextItem DecreaseItem = new IntCodeTextItem(Decrease, "使用");
        }

        /// <summary>
        /// 销售渠道(套餐和充值项)
        /// </summary>
        [Obsolete("要去掉，改到主数据里")]
        public static class SalesChannels
        {
            public const int All = 0;

            /// <summary>
            /// 默认渠道
            /// </summary>
            public const int Default = 1;

            /// <summary>
            /// 手机支付
            /// </summary>
            public const int Mobile = 2;

            public static readonly IntCodeTextItem DefaultItem = new IntCodeTextItem(Default, "默认价格");
            public static readonly IntCodeTextItem MobileItem = new IntCodeTextItem(Mobile, "手机支付");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { DefaultItem, MobileItem };
            }
        }

        /// <summary>
        /// 套餐购买单状态
        /// </summary>
        public static class PackagePurchaseBillStatus
        {
            public const int All = 0;
            /// <summary>
            /// 未支付
            /// </summary>
            public const int Enabled = 1;
            /// <summary>
            /// 已锁定
            /// </summary>
            public const int Disabled = 2;
            /// <summary>
            /// 已删除
            /// </summary>
            public const int Deleted = 3;
            /// <summary>
            /// 已完成
            /// </summary>
            public const int Finished = 4;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem EnabledItem = new IntCodeTextItem(Enabled, "未支付");
            public static readonly IntCodeTextItem DisabledItem = new IntCodeTextItem(Disabled, "已锁定");
            public static readonly IntCodeTextItem DeletedItem = new IntCodeTextItem(Deleted, "已删除");
            public static readonly IntCodeTextItem FinishedItem = new IntCodeTextItem(Finished, "已完成");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, EnabledItem, DisabledItem, DeletedItem, FinishedItem };
            }
        }

        /// <summary>
        /// 资产类型
        /// </summary>
        public static class AssetType
        {
            /// <summary>
            /// 余额
            /// </summary>
            public const int Balance = 0x01;

            /// <summary>
            /// 积分
            /// </summary>
            public const int Point = 0x02;
        }
        
        /// <summary>
        /// 单据类型
        /// </summary>
        public static class BillTypes
        {
            public const int Other = 1;

            public const int All = 1000;
            /// <summary>
            /// 预约单
            /// </summary>
            public const int BookingBill = 1001;
            /// <summary>
            /// 维修单
            /// </summary>
            public const int MaintenanceBill = 1002;
            /// <summary>
            /// 派工单
            /// </summary>
            public const int WorkingBill = 1003;
            /// <summary>
            /// 领料单
            /// </summary>
            public const int MaterialRequisitionBill = 1004;
            /// <summary>
            /// 退料单
            /// </summary>
            public const int MaterialReturnedBill = 1005;
            /// <summary>
            /// 套餐购买单
            /// </summary>
            public const int PackagePurchaseBill = 1006;
            /// <summary>
            /// 维修结算单
            /// </summary>
            public const int SettlementBill = 1007;
            /// <summary>
            /// 资金入账单
            /// </summary>
            public const int CapitalIncreaseBill = 1008;
            /// <summary>
            /// 资金出帐单
            /// </summary>
            public const int CapitalDecreaseBill = 1009;
            /// <summary>
            /// 入库单
            /// </summary>
            public const int StockIncreaseBill = 1010;
            /// <summary>
            /// 出库单
            /// </summary>
            public const int StockDecreaseBill = 1011;
            /// <summary>
            /// 充值单
            /// </summary>
            public const int RechargeBill = 1012;

            public static string GetText(int code)
            {
                if (BookingBill == code)
                {
                    return "预约单";
                }
                else if (MaintenanceBill == code)
                {
                    return "维修单";
                }
                else if (WorkingBill == code)
                {
                    return "派工单";
                }
                else if (MaterialRequisitionBill == code)
                {
                    return "领料单";
                }
                else if (MaterialReturnedBill == code)
                {
                    return "退料单";
                }
                else if (PackagePurchaseBill == code)
                {
                    return "套餐购买单";
                }
                else if (SettlementBill == code)
                {
                    return "维修结算单";
                }
                else if (CapitalIncreaseBill == code)
                {
                    return "资金入账单";
                }
                else if (CapitalDecreaseBill == code)
                {
                    return "资金出帐单";
                }
                else if (StockIncreaseBill == code)
                {
                    return "入库单";
                }
                else if (StockDecreaseBill == code)
                {
                    return "入库单";
                }
                else if (RechargeBill == code)
                {
                    return "充值单";
                }
                else if (Other == code)
                {
                    return "其它";
                }
                return string.Format("unknown{0}", code);
            }
        }

        /// <summary>
        /// 销售价格对应的目标类型
        /// </summary>
        public static class SalePriceTargetTypes
        {
            public const int All = 0;

            /// <summary>
            /// 套餐
            /// </summary>
            public const int Package = 1;

            /// <summary>
            /// 充值项目
            /// </summary>
            public const int RechargeItem = 2;
        }

        /// <summary>
        /// 充值渠道
        /// </summary>
        public static class RechargeChannels
        {
            public const int All = 0;

            /// <summary>
            /// 充值项
            /// </summary>
            public const int RechargeItem = 1;

            public static readonly IntCodeTextItem RechargeItemItem = new IntCodeTextItem(RechargeItem, "充值项");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { RechargeItemItem };
            }
        }


        /// <summary>
        /// 公共的账单状态
        /// </summary>
        public static class CommonBillStatus
        {
            public const int All = 0;
            /// <summary>
            /// 未支付
            /// </summary>
            public const int Enabled = 1;
            /// <summary>
            /// 已锁定
            /// </summary>
            public const int Disabled = 2;
            /// <summary>
            /// 已删除
            /// </summary>
            public const int Deleted = 3;
            /// <summary>
            /// 已完成（已支付)
            /// </summary>
            public const int Finished = 4;

            public static readonly IntCodeTextItem AllItem = new IntCodeTextItem(All, "全部");
            public static readonly IntCodeTextItem EnabledItem = new IntCodeTextItem(Enabled, "未支付");
            public static readonly IntCodeTextItem DisabledItem = new IntCodeTextItem(Disabled, "已锁定");
            public static readonly IntCodeTextItem DeletedItem = new IntCodeTextItem(Deleted, "已删除");
            public static readonly IntCodeTextItem FinishedItem = new IntCodeTextItem(Finished, "已完成");

            public static IntCodeTextItem[] Enumerate()
            {
                return new IntCodeTextItem[] { AllItem, EnabledItem, DisabledItem, DeletedItem, FinishedItem };
            }

            public static string GetText(int code)
            {
                if (code == EnabledItem.Code)
                {
                    return EnabledItem.Text;
                }
                else if (code == DisabledItem.Code)
                {
                    return DisabledItem.Text;
                }
                else if (code == DeletedItem.Code)
                {
                    return DeletedItem.Text;
                }
                else if (code == FinishedItem.Code)
                {
                    return FinishedItem.Text;
                }
                return "unknown";
            }
        }
    }
}
